<?php

namespace app\controller\api\v1\recruit;

use app\Request;
use app\model\v1\recruit\RecruitLanguage as languageModel;
use app\services\product\category\StoreProductCategoryServices;
use app\validate\api\recruit\authentValidate;


/**
 * 求职招聘
 * Class RecruitCollection
 * @package app\controller\api\recruit
 */
class RecruitLanguage
{
    protected $services;
    protected $model;
    protected $userinfo = [];

    public function __construct(StoreProductCategoryServices $services)
    {
        $this->services = $services;
        $this->model = new languageModel();
    }



    /**
     * 个人中心 - 获取常用语列表
     * @param Request $request
     * @return \think\Response
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getLanguageList(Request $request)
    {
        try {
            $uid = $request->uid();

            $data = languageModel::getRecruitLanguageList($uid);
            return app('json')->success($data);
        } catch (\Throwable $e) {
            return app('json')->fail($e->getMessage());
        }
    }

    /**
     * 个人中心 - 添加常用语
     * @param Request $request
     * @return \think\Response
     */
    public function createLanguage(Request $request)
    {
        $param = $request->post();
        if(empty($param["content"])) return app('json')->fail('content常用语不能为空');

        $param['user_id'] = $request->uid();
        try {
            $res = languageModel::createLanguage($param);
            if($res > 0){
                return app('json')->success('常用语添加成功');
            }
            return app('json')->fail('常用语添加fail');
        } catch (\Throwable $e) {
            return app('json')->fail($e->getMessage());
        }
    }


    /**
     * 个人中心 - 编辑常用语
     * @param Request $request
     * @return \think\Response
     */
    public function updateLanguage(Request $request)
    {
        $param = $request->post();
        if(empty($param["id"])) return app('json')->fail('id不能为空');
        if(empty($param["content"])) return app('json')->fail('content常用语不能为空');

        $param['user_id'] = $request->uid();
        try {
            $res = languageModel::updateLanguage($param);
            if($res >= 0){
                return app('json')->success('常用语编辑成功');
            }
            return app('json')->fail('常用语编辑fail');
        } catch (\Throwable $e) {
            return app('json')->fail($e->getMessage());
        }
    }






}